﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
namespace hoangnam12
{
    public partial class Search : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            DataSet ds = SampleData();
            clPager.PageSize = 2; // số sản phẩm mỗi trang
            clPager.DataSource = ds.Tables[0].DefaultView; // lấy dữ liệu từ database
            clPager.BindToControl = DataList2; // có thể dùng cho repeater hoặc datalist..
            DataList2.DataSource = clPager.DataSourcePaged;
            
        }

        #region uuuu
        private DataSet SampleData()
        {
            string text = TextBox1.Text;
            Console.Write(text);
            string sql = "select [MaSP], [TenSP], [GiaSP], [HinhSP] FROM [SanPham] where TenSP like '%" + text + "%' ";
            string constring = "Data Source=ADMIN;Initial Catalog=QLBH;Integrated Security=True";
            SqlConnection conn = new SqlConnection(constring);
            
                conn.Open();
                SqlDataAdapter da = new SqlDataAdapter(sql, conn);


                DataSet ds = new DataSet();

                da.Fill(ds);
                DataTable dt = ds.Tables.Add("SampleData");

                dt.Columns.Add("MaSP", typeof(string));
                dt.Columns.Add("TenSP", typeof(string));
                dt.Columns.Add("GiaSP", typeof(string));
                dt.Columns.Add("HinhSP", typeof(string));

                return ds;
        

                conn.Close();
            
            
            
        }
        #endregion
    }
}